/*
 * acm1489.c
 *
 *  Created on: 11 Apr 2010
 *      Author: xuxu
 */

#include<stdio.h>
int main()
{
	int n;
	int i,j;
	while(scanf("%d",&n)!=EOF)
	{
		if(0==n%2||n==1)
		{
			printf("2^? mod %d = 1\n",n);
			continue;
		}
		j=2;
		for(i=1;;i++)
		{
			if(1==(j=j%n))
			{
				printf("2^%d mod %d = 1\n",i,n);
				break;
			}
			j*=2;
		}

	}
	return 0;
}
